<template>
    <section class="content">
        <section class="logo">
            <img src="~path_img/logo.png" alt="">
        </section>
        <van-form @submit="onSubmit">
            <van-field
                    type="password"
                    v-model="form_data.password"
                    center
                    clearable
                    label="原密码"
                    placeholder="请输入原密码"
                    :rules="[{ required: true }]"
            />
            <van-field
                    type="password"
                    v-model="form_data.npassword"
                    center
                    clearable
                    label="新密码"
                    placeholder="请输入新密码"
                    :rules="[{ required: true }]"
            />
            <van-field
                    type="password"
                    v-model="form_data.configpassword"
                    center
                    clearable
                    label="确认新密码"
                    placeholder="请输入密码"
                    :rules="querenmima"
            />
            <div style="margin: 16px;">
                <van-button round block type="info" color="#f5bb19" native-type="submit">提交</van-button>
            </div>
        </van-form>
    </section>
</template>

<script>
    export default {
        name: "xiugamima",
        data(){
            return{
                form_data: {
                    password: '',
                    npassword: '',
                    configpassword:''
                },
                querenmima: [{
                    required: true,
                    message: '请输入确认密码'
                },{
                    validator: value => {
                        if(value != this.form_data.npassword) return false;
                    },
                    message: '两次密码不一致'
                }]
            }
        },
        mounted() {
            window.dingshu = null;
        },
        methods: {
            onSubmit(){
                let _this = this
                this.$https.fetchPost('/xiugaimima',this.form_data).then( res => {
                    if(res.code == 0){
                        this.$toast('修改成功');
                        setTimeout((res) => {
                            _this.$router.push('/gerenxinxi')
                        },1000)
                    }
                    else{
                        this.$toast(res.msg);
                    }
                })
            },
            fun_code(){
                let reg = /^1[3456789]\d{9}$/,_this = this;
                if(!reg.test(this.form_data.iphone)){
                    this.$toast('请输入正确的手机号');
                }
                else{
                    _this.disabled_btn = true;
                    window.dingshi = setInterval(()=> {
                        if(_this.miaoshu > 0){
                            _this.miaoshu = _this.miaoshu - 1 ;
                            _this.code_text = _this.miaoshu;
                        }
                        else{
                            clearInterval(window.dingshi);
                            _this.miaoshu = 10;
                            _this.disabled_btn = false;
                            _this.code_text = '重新获取验证码';
                        }

                    },1000)
                }
            }
        }
    }
</script>

<style scoped lang="less">

    .logo{
        padding: 1rem 0 1.5rem;
        img{
            width: 2.5rem;
        }
    }
</style>
